/*
*************************************
* PocketGTT
*************************************
This file is part of PocketGTT.

PocketGTT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PocketGTT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PocketGTT.  If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 1.0

Rectangle {
    id:pager
    //anchors.fill: parent

    property bool enableKeys: true
    property QtObject model: PagerModel { p_width: pager.width; p_height: pager.height}
    property bool isHorizontal: true

    property int index: view.currentIndex
    property Item item: view.currentItem

    signal indexChanged


    ListView {

        id: view
        anchors.fill: pager
        model: pager.model
        orientation: if (isHorizontal){ListView.Horizontal;} else {ListView.Vertical}
        snapMode: ListView.SnapOneItem;
        flickDeceleration: 500
        highlightFollowsCurrentItem: true
        highlightRangeMode: ListView.StrictlyEnforceRange
        preferredHighlightBegin: 0; preferredHighlightEnd: 0
        cacheBuffer: width;
        focus: pager.focus
        onCurrentIndexChanged: pager.indexChanged()
        Keys.onLeftPressed: {
            if (enableKeys && isHorizontal && (currentIndex > 0 )) {
                currentIndex = currentIndex-1;
            }



        }
        Keys.onRightPressed: {
            if (enableKeys && isHorizontal && (currentIndex < count))
            currentIndex = currentIndex+1;}
        Keys.onUpPressed: {
            if (enableKeys && !isHorizontal && (currentIndex > 0 ))
            currentIndex = currentIndex-1;}
        Keys.onDownPressed: {
            if (enableKeys && !isHorizontal && (currentIndex < count))
            currentIndex = currentIndex+1;}
    }
}
